package com.luyuan.crm.promotion.web;

import javax.annotation.Resource;
import javax.faces.model.ListDataModel;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.luyuan.crm.member.model.MemberLevel;
import com.luyuan.crm.promotion.MemberIntegralPromotion;
import com.luyuan.crm.promotion.MemberIntegralPromotionService;
import com.ruijie.util.StringUtils;
import com.ruijie.web.jsf.action.BaseAction;

@Component("memberIntegralPromotionAction")
@Scope("view")
public class MemberIntegralPromotionAction extends BaseAction {
    @Resource(name = "memberIntegralPromotionService")
    private MemberIntegralPromotionService memberIntegralPromotionService;

    private MemberIntegralPromotion memberIntegralPromotion;

    public MemberIntegralPromotion getMemberIntegralPromotion() {
        String memberLevel = getRequestParameter("memberLevel");
        if (StringUtils.isNotEmpty(memberLevel)) {
            memberIntegralPromotion = memberIntegralPromotionService
                    .findByMemberLevel(MemberLevel.valueOf(memberLevel));
        }
        return memberIntegralPromotion;
    }

    public void update() {
        memberIntegralPromotionService.updateMemberLevelPromotion(memberIntegralPromotion);

        addGlobalI18nMessage("crud_update_success_msg");
    }

    public ListDataModel getTableModel() {
        return new ListDataModel(memberIntegralPromotionService.getAllMemberLevelPromotion());
    }
}
